package com.ruoyi.web.controller.business;

import java.io.IOException;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.exception.file.InvalidExtensionException;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TbUserInfo;
import com.ruoyi.system.service.ITbUserInfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 客户管理Controller
 * 
 * @author ruoyi
 * @date 2024-05-14
 */
@RestController
@RequestMapping("/business/info")
public class TbUserInfoController extends BaseController
{
    @Autowired
    private ITbUserInfoService tbUserInfoService;

    /**
     * 查询客户管理列表
     */
    @PreAuthorize("@ss.hasPermi('business:info:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbUserInfo tbUserInfo)
    {
        startPage();
        List<TbUserInfo> list = tbUserInfoService.selectTbUserInfoList(tbUserInfo);
        return getDataTable(list);
    }

    /**
     * 导出客户管理列表
     */
    @PreAuthorize("@ss.hasPermi('business:info:export')")
    @Log(title = "客户管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbUserInfo tbUserInfo)
    {
        List<TbUserInfo> list = tbUserInfoService.selectTbUserInfoList(tbUserInfo);
        ExcelUtil<TbUserInfo> util = new ExcelUtil<TbUserInfo>(TbUserInfo.class);
        util.exportExcel(response, list, "客户管理数据");
    }

    /**
     * 获取客户管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:info:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tbUserInfoService.selectTbUserInfoById(id));
    }

    /**
     * 新增客户管理
     */
    @PreAuthorize("@ss.hasPermi('business:info:add')")
    @Log(title = "客户管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbUserInfo tbUserInfo)
    {
        return toAjax(tbUserInfoService.insertTbUserInfo(tbUserInfo));
    }

    /**
     * 修改客户管理
     */
    @PreAuthorize("@ss.hasPermi('business:info:edit')")
    @Log(title = "客户管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbUserInfo tbUserInfo)
    {
        return toAjax(tbUserInfoService.updateTbUserInfo(tbUserInfo));
    }

    /**
     * 删除客户管理
     */
    @PreAuthorize("@ss.hasPermi('business:info:remove')")
    @Log(title = "客户管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tbUserInfoService.deleteTbUserInfoByIds(ids));
    }


//    @PreAuthorize("@ss.hasPermi('business:info:upload')")
    @PostMapping("/imageUpload")
    @Anonymous
    public AjaxResult imageUpload(@RequestParam("file") MultipartFile file) throws IOException, InvalidExtensionException {
        return success(tbUserInfoService.imageUpload(file));
    }
    @GetMapping("/getInfoList")
    public AjaxResult getInfoList(){
        return success(tbUserInfoService.getInfoList());
    }
}
